package com.tgy.algorithm.base._并查集;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

class PersonInfo{
    String identity;
    String githubId;
    String bibiId;

    public PersonInfo(String identity, String githubId, String bibiId) {
        this.identity = identity;
        this.githubId = githubId;
        this.bibiId = bibiId;
    }
}

public class _根据信息获取有几个人 {

    public static void main(String[] args) {

        List<PersonInfo> personInfos = new ArrayList<>();
        personInfos.add(new PersonInfo("1111", "122", "133"));
        personInfos.add(new PersonInfo("2222", "122", "144"));
        personInfos.add(new PersonInfo("3333", "124", "144"));
        UnionFind<PersonInfo> infoUnionFind = new UnionFind<PersonInfo>(personInfos);

        Map<String, PersonInfo> identityMap = new HashMap<>();
        Map<String, PersonInfo> githubIdMap = new HashMap<>();
        Map<String, PersonInfo> bibiIdMap = new HashMap<>();

        for (PersonInfo personInfo : personInfos) {
            String identity = personInfo.identity;
            PersonInfo personInfo1 = identityMap.get(identity);
            if (personInfo1 == null) {
                identityMap.put(identity, personInfo);
            }else {
                infoUnionFind.union(personInfo, personInfo1);
            }

            String githubId = personInfo.githubId;
            PersonInfo personInfo2 = githubIdMap.get(githubId);
            if (personInfo2 == null) {
                githubIdMap.put(githubId, personInfo);
            }else {
                infoUnionFind.union(personInfo, personInfo2);
            }

            String bibiId = personInfo.bibiId;
            PersonInfo personInfo3 = bibiIdMap.get(bibiId);
            if (personInfo3 == null) {

                bibiIdMap.put(bibiId, personInfo);
            }else {
                infoUnionFind.union(personInfo, personInfo3);
            }
        }

        int maps = infoUnionFind.getMaps();
        System.out.println(maps);

    }
}
